package com.caocaog.market.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.caocaog.market.entity.GoodsBase;
import com.caocaog.market.entity.dto.GoodsDTO;
import com.caocaog.market.entity.vo.GoodsVO;
import com.caocaog.market.service.GoodsHubService;
import io.swagger.annotations.Api;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.domain.QueryRequest;
import org.jeecg.common.system.query.PageGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(value = "hub", tags = "商品库信息")
@RequestMapping("/goods/goodsHub")
public class GoodsHubController {

    @Setter(onMethod_ = @Autowired)
    private GoodsHubService goodsHubService;


    @GetMapping(value = "/page")
    public Result<IPage<GoodsBase>> queryPage(GoodsBase goodsBase, QueryRequest queryRequest) {
        Page<GoodsBase> page = PageGenerator.createPageSort(queryRequest);
        return Result.OK(goodsHubService.queryGoodsHubPage(page, goodsBase));
    }


    @GetMapping(value = "/getGoodsHubList")
    public Result<List<GoodsVO>> getGoodsHub(@RequestParam Long shopTypeId) {
        return Result.OK(goodsHubService.getGoodsHubListByShopTypeId(shopTypeId));
    }


    @PostMapping(value = "/addGoodsHub")
    public Result<GoodsVO> addGoodsHub(@RequestBody GoodsDTO goods) {
        return Result.OK(goodsHubService.addGoodsHub(goods));
    }


    @PutMapping(value = "/editGoodsHub")
    public Result<GoodsVO> editGoodsHub(@RequestBody GoodsDTO goods) {
        return Result.OK(goodsHubService.editGoodsHub(goods));
    }


    @DeleteMapping(value = "/deleteGoodsHub")
    public Result<Integer> deleteGoodsHub(@RequestParam String... goodsHubIds) {
        return Result.OK(goodsHubService.deleteGoodsHub(goodsHubIds));
    }


    @PostMapping(value = "/batchImportGoods")
    public Result<Integer> batchImportGoods(@RequestBody List<GoodsDTO> goodsDTOList) {
        return Result.OK(goodsHubService.batchImportGoods(goodsDTOList));
    }


}
